package com.example.zsgc.controller;

import com.example.zsgc.entity.Flower;
import com.example.zsgc.mapper.FlowerMapper;
import com.example.zsgc.tools.Constants;
import com.example.zsgc.tools.PageSupport;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import java.util.List;
import java.util.Map;

@Controller
public class sece {

    @Autowired
    private FlowerMapper flowerMapper;


    @RequestMapping("sect")
    public String login(@RequestParam(value = "name",required = false) String name,
                        @RequestParam(value = "pageIndex",defaultValue = "1")Integer pageIndex,
                        Map<String,Object> map){
        List<Flower> list=null;
        try {
            //设置页面容量
            int pageSize= Constants.pageSize;
            //总数量
            int totalCount= flowerMapper.getNum();
            //总页数
            PageSupport page=new PageSupport();
            page.setCurrentPageNo(pageIndex);
            page.setPageSize(pageSize);
            page.setTotalCount(totalCount);
            int totalPageCount=page.getTotalPageCount();
            //控制页首和页尾
            if (pageIndex>totalPageCount){
                pageIndex=totalPageCount;
            }
            list= flowerMapper.getFl(name,pageIndex,pageSize);
            map.put("list",list);
            //页数
            map.put("totalPageCount",totalPageCount);
            //数据总数
            map.put("totalCount",totalCount);

            map.put("currentPageNo",pageIndex);
        }catch (Exception e){
            e.printStackTrace();
        }
        return "index";
    }

}
